package com.framework.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.framework.dao.SysActiveInfoDao;
import com.framework.entity.sys.SysActiveInfo;
import com.framework.view.SysActiveInfoView;
import com.framework.page.PageUtils;
import com.framework.service.SysActiveInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service("sysActiveInfoService")
@Transactional(rollbackFor = Exception.class)
public class SysActiveInfoServiceImpl extends ServiceImpl<SysActiveInfoDao, SysActiveInfo> implements SysActiveInfoService {

    @Override
    public PageUtils queryActiveList(Map<String, Object> params) {

        if ("".equals(params.get("startDate"))){
            params.put("startDate",null);
        }
        if ("".equals(params.get("endDate"))){
            params.put("endDate",null);
        }
        Integer pageSize = Integer.valueOf(params.get("limit").toString());
        Integer currPage = Integer.valueOf(params.get("page").toString());
        params.put("start",(currPage-1)*pageSize);
        params.put("limit",pageSize);
        List<SysActiveInfoView> list = this.baseMapper.queryActiveList(params);
        Integer totalCount = this.baseMapper.queryActiveCount(params);
        PageUtils pageUtils=new PageUtils(list,totalCount,pageSize,currPage);
        return pageUtils;
    }

    @Override
    public void insertActiveInfo(SysActiveInfo sysActiveInfo) {
        sysActiveInfo.setCreateTime(new Date());
        this.baseMapper.insertActiveInfo(sysActiveInfo);
    }

    @Override
    public SysActiveInfo queryActiveInfoById(Long activeInfoId) {
        return this.baseMapper.queryActiveInfoById(activeInfoId);
    }

    @Override
    public void updateActiveById(SysActiveInfo sysActiveInfo) {
        this.baseMapper.updateActiveById(sysActiveInfo);
    }

    @Override
    public void deleteActiveInfoById(Long activeInfoId) {
        this.baseMapper.deleteActiveInfoById(activeInfoId);
    }

    @Override
    public List<SysActiveInfo> queryActiveInfoListByActiveId(Long activeId) {
        return baseMapper.queryActiveInfoListByActiveId(activeId);
    }

    @Override
    public List<SysActiveInfo> queryOnActiveInfoByActiveId(Long activeId) {
        return baseMapper.queryOnActiveInfoByActiveId(activeId);
    }

}
